﻿//Главная форма приложения
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using IDE;
using CommonClasses.Services;
using DomainModelEditor;
using CommonClasses.Logger;
using Descriptions_DomainModel.Model;
using Eco.ObjectRepresentation;
using Descriptions_DomainModelLoader;

namespace AutoCompleteTest
{
    /// <summary>
    /// Класс для визуального тестирования IronHand.IntelliSenseControl
    /// Для запуска нужны конфиги DomainModel, LoggerManager
    ///                   ресурсы Logger'a
    /// </summary>
    public partial class TestForm : Form
    {
        /// <summary>
        /// Менеджер логгеров
        /// </summary>
        private ILoggingManagement mainLog;
        /// <summary>
        /// Локальный логгер
        /// </summary>
        private ILogger worklog;
        /// <summary>
        /// ECO's WhiteBoard
        /// </summary>
        private IDEEcoSpace ecoSpace;

        /// <summary>
        /// Инициализирует логгеры, ECOSpace, DomainModel, сам тестируемый контрол
        /// </summary>
        public TestForm()
        {
            InitializeComponent();
            
            mainLog = LoggerManager.CreateOnce(".\\LoggerManager.ih.config", ".\\logs");
            worklog = mainLog.GetLogger("ecoSpace");
            ecoSpace = new IDEEcoSpace(worklog);
            ecoSpace.Active = true;

            new DomainModelsLoader(ecoSpace).LoadDeviceDescriptionsFromMainFile(AutoCompleteTest.Properties.Settings.Default.DomainModelPath);
            ecoSpace.GetEcoService<ITranslatorService>().Initialize(
                ecoSpace.Ocl.Evaluate("DomainModel.allInstances->first").AsObject as DomainModel);
            var domainModel = ecoSpace.Ocl.Evaluate("DomainModel.allinstances->first").AsObject as DomainModel;

            textBoxWithIntelliSense1.Initialize(ecoSpace, domainModel, this, new List<string>() { "GraphVariable" });
        }

        /// <summary>
        /// Программно запрашивает текст из контрола
        /// </summary>
        /// <param name="sender">-</param>
        /// <param name="e">-</param>
        private void GetText_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBoxWithIntelliSense1.Text;
        }
        /// <summary>
        /// Программно помещает текст в контрол
        /// </summary>
        /// <param name="sender">-</param>
        /// <param name="e">-</param>
        private void SetText_Click(object sender, EventArgs e)
        {
            textBoxWithIntelliSense1.Text = textBox1.Text;
        }
    }
}
